package com.web.music.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class Album implements PersistentObject {
	
	@Id
	private Long id;
	
	private String title;
	
	private String review;
	
	@ManyToOne
	private Artist artist = null;	

	@OneToMany(mappedBy="album")
	private List<Track> tracks;
	
	@ManyToMany
	private List<Genre> genres = new ArrayList<Genre>();
	
	public Album() {
		super();
	}

	public Album(Long id, String review, String title) {
		super();
		this.id = id;
		this.review = review;
		this.title = title;
	}
		
	public Album(Long id, String title, String review, Artist artist, List<Genre> genres, List<Track> tracks) {
		super();
		this.artist = artist;
		this.genres = genres;
		this.id = id;
		this.review = review;
		this.title = title;
		this.tracks = tracks;
	}
	
	public String getTitle(){
		return title;
	}
	
	public List<Track> getTracks() {
		return tracks;
	}

	public void setTracks(List<Track> tracks) {
		this.tracks = tracks;
	}

	public String getReview(){
		return review;
	}

	public void setReview(String review ){
		this.review = review;
	}

	public void setTitle(String title ){
		this.title = title;
	}

	public List<Genre> getGenres() {
		return genres;
	}

	public void setGenres(List<Genre> genres) {
		this.genres = genres;
	}

	public Artist getArtist() {
		return artist;
	}

	public void setArtist(Artist artist) {
		this.artist = artist;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public boolean equals(Object obj) {
		boolean result = true;
		if (obj instanceof Album) {
			
			result = this.id.equals(((Album) obj).getId())
						&& this.title.equals(((Album) obj).getTitle());
			return result;
		}
		return false;
	}

	@Override
	public String toString() {
		return this.id + " " + this.title;
	}	
	
	@Override
	public int hashCode() {
		return toString().hashCode();
	}

}
